package edu.gdin.ecommerce.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

import edu.gdin.ecommerce.model.Func;
import edu.gdin.ecommerce.service.IFuncService;

@Component("funcAction")
@Scope("prototype")
public class FuncAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4414105600689121755L;
	
	private IFuncService funcService;
	private List<Func> funcs;
	private Func func;

	private String msg = "";
	
	public IFuncService getFuncService() {
		return funcService;
	}
	@Resource
	public void setFuncService(IFuncService funcService) {
		this.funcService = funcService;
	}
	public List<Func> getFuncs() {
		return funcs;
	}
	public void setFuncs(List<Func> funcs) {
		this.funcs = funcs;
	}
	public Func getFunc() {
		return func;
	}
	public void setFunc(Func func) {
		this.func = func;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	
	// ----------  methods  -----------
	
	
	public String getAllFuncs() {
		this.funcs = this.funcService.getAllFuncs();
		return "getAllFuncs";
	}
	
	
	public String preAddFunc() {
		this.funcs = this.funcService.getAllFuncs();
		return "preAddFunc";
	}

	
	public String addFunc() {
		if(this.funcService.isExist(this.func)) {
			this.addFieldError("error", "已存在同名权限 ！");
			return "preAddFunc";
		}
		this.func.setType(1); //type属性不用!
		this.funcService.addFunc(this.func);
		
		return "addFunc";
	}
	
}
